﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CircuitBoardApplication.Classes.Components.Gates
{
    class gateOR : Gate
    {
        private int input2;
        private bool isInputSet = false;
        public gateOR(int id, String type, int value, int x, int y)
            : base(id, type, value, x, y)
        {
            ID = id;
            Type = type;
            Value = value;
            X = x;
            Y = y;
        }

        public int Input2
        {
            get { return this.input2; }
            set { this.input2 = value; }
        }

        public override void DrawItself(System.Drawing.Graphics gr, System.Windows.Forms.ImageList il)
        {
            int diameter = 2 * ComponentMain.radius;
            gr.DrawImage(il.Images[4], this.X - ComponentMain.radius, this.Y - ComponentMain.radius, diameter, diameter);
        }

        public override void setInputsFromConnections(Connection conn)
        {
            if (conn.RECEIVINGComponent == this)
            {
                if (!isInputSet)
                {
                    this.Input = conn.SENTComponent.Value;
                    isInputSet = true;
                }
                else
                    this.input2 = conn.SENTComponent.Value;
            }

        }

        public override string ToString()
        {
            return base.ToString() + " Input2:" + Input2.ToString();
        }

        public override int Calculate()
        {
            if ((Input == 1) || (Input2 == 1))
                return 1;
            else
                return 0;
        }
    }
}
